package com.controller;

import com.pojo.Order;
import com.service.OrdersService;
import com.util.ConstUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.security.Principal;
import java.util.HashMap;
import java.util.Map;

/**
 * @author mornd
 * @date 2020/12/1 - 14:54
 */
@Controller
@RequestMapping("/orders")
public class OrdersController {
    @Autowired
    private OrdersService ordersService;

    /**
     * 添加预定的房间订单
     *
     * @param order
     * @return
     */
    @ResponseBody
    @RequestMapping("/addOrder")
    public Map<String, Object> addOrder(Principal principal, Order order) {
        Map<String, Object> maps = new HashMap<String, Object>();
        if (ordersService.addOrders(principal, order) > 0) {
            maps.put(ConstUtils.SUCCESS, true);
            maps.put(ConstUtils.MESSAGE, "预定房间成功！");
        } else {
            maps.put(ConstUtils.SUCCESS, false);
            maps.put(ConstUtils.MESSAGE, "预定房间失败，请重试！");
        }
        return maps;
    }
}
